home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1996 #3 / AmigaPlus_CD-ROM-EXTRA_Nr.3.bin / aminet-spiele / zwei spieler / lordofhosts / lohsrc.lzh / openclose.c < prev    next >
C/C++ Source or Header  |  1991-05-10  |  10KB  |  282 lines

  1. /* LORD OF HOSTS - openclose.c --- Öffnen und Schließen von Libs - Fenster... */
  2.  
  3. #include "Lord.h"
  4.  
  5. struct MsgPort    *MPort;
  6. struct IOStdReq   *IOReq;
  7. ULONG             JoyMouseData;
  8. struct Screen     *MyScreen;
  9. struct Window     *MyWindow;
  10. struct RastPort   *RP;
  11. struct ViewPort   *VP;
  12. struct BitMap     *BM,PiecesBM;
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase    *GfxBase;
  15. struct ReqLib     *ReqBase;
  16. struct TextFont   *MyFont;
  17. struct Process    *MyProcess;
  18. APTR              OldErrorWindow;
  19. extern struct FileRequester MyFileReqStruct;
  20.  
  21. UWORD MyColorMap[16] = {
  22.     0x006,0xFFF,0xE00,0x800,0xF77,0xFCA,0xD61,0xFFF,
  23.     0xF91,0x46F,0xFC0,0x0F0,0x333,0x222,0x555,0x000
  24. };
  25.  
  26. struct TextAttr TheFont =
  27. {
  28.    (UBYTE *)"topaz.font",
  29.    TOPAZ_EIGHTY,
  30.    FS_NORMAL,
  31.    FPF_ROMFONT
  32. };
  33.  
  34. struct NewScreen TheScreen =
  35. {
  36.    0, 0, 320, 200, 4,
  37.    0, 1, NULL,
  38.    CUSTOMSCREEN|SCREENBEHIND,
  39.    &TheFont,
  40.    (UBYTE *)"LORD OF HOSTS © 1991 Tim Pietzcker",
  41.    NULL,NULL
  42. };
  43.  
  44. struct NewWindow TheWindow =
  45. {
  46.    0, 0, 320, 200, 0, 1,
  47.    MOUSEBUTTONS|MENUPICK,
  48.    ACTIVATE|SMART_REFRESH|BACKDROP|BORDERLESS,
  49.    NULL, NULL, NULL, NULL, NULL,
  50.    0, 0, 0, 0,
  51.    CUSTOMSCREEN
  52. };
  53.  
  54. /* Menü Special */
  55. #define M_SUBW1 (8*4 + LOWCHECKWIDTH)
  56. #define M_SUBW2 (8*18 + LOWCHECKWIDTH)
  57. #define M_WIDTH3 (8*23 + LOWCOMMWIDTH)
  58.  
  59. struct IntuiText on_t =
  60. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"On", NULL};
  61. struct IntuiText off_t =
  62. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Off", NULL};
  63.  
  64. struct IntuiText nohelp_t =
  65. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"No Help", NULL};
  66. struct IntuiText showknown_t =
  67. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Show Known Values", NULL};
  68. struct IntuiText showall_t =
  69. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Show All Values", NULL};
  70.  
  71. struct IntuiText explain_t =
  72. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Explain Invalid Move", NULL};
  73. struct IntuiText switch_t =
  74. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Switch Sides", NULL};
  75. struct IntuiText setspeed_t =
  76. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Set JoyMouse Speed...", NULL};
  77. struct IntuiText joymouse_t =
  78. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"JoyMouse", NULL};
  79. struct IntuiText mode2_t =
  80. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Player 2 Help Mode", NULL};
  81. struct IntuiText mode1_t =
  82. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Player 1 Help Mode", NULL};
  83. struct IntuiText redo_t =
  84. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Redo", NULL};
  85. struct IntuiText undo_t =
  86. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Undo", NULL};
  87.  
  88. /* MenuSubItems */
  89. struct MenuItem off_m =
  90. {  NULL, 69, 10, M_SUBW1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  91.    0x0001, (APTR)&off_t, NULL, NULL, NULL, NULL };
  92. struct MenuItem on_m =
  93. {  &off_m, 69, 0, M_SUBW1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|CHECKED,
  94.    0x0002, (APTR)&on_t, NULL, NULL, NULL, NULL };
  95.  
  96. struct MenuItem showall1_m =
  97. {  NULL, 69, 20, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  98.    0x0003, (APTR)&showall_t, NULL, NULL, NULL, NULL };
  99. struct MenuItem showknown1_m =
  100. {  &showall1_m, 69, 10, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  101.    0x0005, (APTR)&showknown_t, NULL, NULL, NULL, NULL };
  102. struct MenuItem nohelp1_m =
  103. {  &showknown1_m, 69, 0, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|
  104.    CHECKED, 0x0006, (APTR)&nohelp_t, NULL, NULL, NULL, NULL };
  105.  
  106. struct MenuItem showall2_m =
  107. {  NULL, 69, 20, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  108.    0x0003, (APTR)&showall_t, NULL, NULL, NULL, NULL };
  109. struct MenuItem showknown2_m =
  110. {  &showall2_m, 69, 10, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  111.    0x0005, (APTR)&showknown_t, NULL, NULL, NULL, NULL };
  112. struct MenuItem nohelp2_m =
  113. {  &showknown2_m, 69, 0, M_SUBW2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|
  114.    CHECKED, 0x0006, (APTR)&nohelp_t, NULL, NULL, NULL, NULL };
  115.  
  116. /* MenuItems */
  117. struct MenuItem explain_m =
  118. {  NULL, 0, 70, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  119.    (APTR)&explain_t, NULL, (BYTE)'E', NULL, NULL };
  120. struct MenuItem switch_m =
  121. {  &explain_m, 0, 60, M_WIDTH3, 10, ITEMTEXT|HIGHCOMP, NULL,
  122.    (APTR)&switch_t, NULL, NULL, NULL, NULL };
  123. struct MenuItem setspeed_m =
  124. {  &switch_m, 0, 50, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  125.    (APTR)&setspeed_t, NULL, (BYTE)'J', NULL, NULL };
  126. struct MenuItem joymouse_m =
  127. {  &setspeed_m, 0, 40, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
  128.    (APTR)&joymouse_t, NULL, NULL, &on_m, NULL };
  129. struct MenuItem mode2_m =
  130. {  &joymouse_m, 0, 30, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
  131.    (APTR)&mode2_t, NULL, NULL, &nohelp2_m, NULL };
  132. struct MenuItem mode1_m =
  133. {  &mode2_m, 0, 20, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHBOX, NULL,
  134.    (APTR)&mode1_t, NULL, NULL, &nohelp1_m, NULL };
  135. struct MenuItem redo_m =
  136. {  &mode1_m, 0, 10, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  137.    (APTR)&redo_t, NULL, (BYTE)'R', NULL, NULL };
  138. struct MenuItem undo_m =
  139. {  &redo_m, 0, 0, M_WIDTH3, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  140.    (APTR)&undo_t, NULL, (BYTE)'U', NULL, NULL };
  141.  
  142. /* Menü Board */
  143. #define M_WIDTH2 (8*21 + LOWCHECKWIDTH)
  144.  
  145. struct IntuiText rnd2_t =
  146. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Unbalanced Random", NULL};
  147. struct IntuiText rnd1_t =
  148. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Balanced Random", NULL};
  149. struct IntuiText std2_t =
  150. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Standard Rotated 90°", NULL};
  151. struct IntuiText std1_t =
  152. {  0, 1, JAM1, LOWCHECKWIDTH, 1, &TheFont, (UBYTE *)"Standard", NULL};
  153.  
  154. /* MenuItems */
  155. struct MenuItem rnd2_m =
  156. {  NULL, 0, 30, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  157.    0x0007, (APTR)&rnd2_t, NULL, NULL, NULL, NULL };
  158. struct MenuItem rnd1_m =
  159. {  &rnd2_m, 0, 20, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  160.    0x000B, (APTR)&rnd1_t, NULL, NULL, NULL, NULL };
  161. struct MenuItem std2_m =
  162. {  &rnd1_m, 0, 10, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
  163.    0x000D, (APTR)&std2_t, NULL, NULL, NULL, NULL };
  164. struct MenuItem std1_m =
  165. {  &std2_m, 0, 0, M_WIDTH2, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKED|CHECKIT,
  166.    0x000E, (APTR)&std1_t, NULL, NULL, NULL, NULL };
  167.  
  168. /* Menü Game */
  169. #define M_WIDTH1 (8*14 + LOWCOMMWIDTH)
  170.  
  171. struct IntuiText quit_t =
  172. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Quit", NULL};
  173. struct IntuiText about_t =
  174. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"About", NULL};
  175. struct IntuiText rules_t =
  176. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Rules...", NULL};
  177. struct IntuiText save_t =
  178. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Save Game...", NULL};
  179. struct IntuiText load_t =
  180. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Load Game...", NULL};
  181. struct IntuiText begin_t =
  182. {  0, 1, JAM1, 0, 1, &TheFont, (UBYTE *)"Begin Game", NULL};
  183.  
  184. /* MenuItems */
  185. struct MenuItem quit_m =
  186. {  NULL, 0, 50, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  187.    (APTR)&quit_t, NULL, (BYTE)'Q', NULL, NULL };
  188. struct MenuItem about_m =
  189. {  &quit_m, 0, 40, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  190.    (APTR)&about_t, NULL, (BYTE)'A', NULL, NULL };
  191. struct MenuItem rules_m =
  192. {  &about_m, 0, 30, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  193.    (APTR)&rules_t, NULL, (BYTE)'?', NULL, NULL };
  194. struct MenuItem save_m =
  195. {  &rules_m, 0, 20, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  196.    (APTR)&save_t, NULL, (BYTE)'S', NULL, NULL };
  197. struct MenuItem load_m =
  198. {  &save_m, 0, 10, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  199.    (APTR)&load_t, NULL, (BYTE)'L', NULL, NULL };
  200. struct MenuItem begin_m =
  201. {  &load_m, 0, 0, M_WIDTH1, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ, NULL,
  202.    (APTR)&begin_t, NULL, (BYTE)'B', NULL, NULL };
  203.  
  204. /* Gesamt (Haupt-) Menü */
  205. struct Menu special_m =
  206. {  NULL, 4*21, 0, 4*16, 10, MENUENABLED, (BYTE *)"Special", &undo_m };
  207. struct Menu board_m =
  208. {  &special_m, 4*10-1, 0, 4*11+1, 10, MENUENABLED, (BYTE *)"Board", &std1_m };
  209. struct Menu game_m =
  210. {  &board_m, 2, 0, 4*9+1, 10, MENUENABLED, (BYTE *)"Game", &begin_m };
  211.  
  212. void errorstop(char *message)
  213. {
  214.    puts(message);
  215.    Delay(100);
  216.    close_all();
  217. }
  218.  
  219. void open_all(void)
  220. {
  221.    int i,j; long sec,mic;
  222.    if (!(IntuitionBase = OpenLibrary("intuition.library",0)))
  223.       errorstop("No intuition.library!");
  224.    if (!(GfxBase = OpenLibrary("graphics.library",0)))
  225.       errorstop("No graphics.library!");
  226.    if (!(ReqBase = OpenLibrary("req.library",0)))
  227.       errorstop("No req.library!\n Either copy the supplied req.library to"
  228.                 " your LIBS: directory or\n Assign LIBS: \"\" before running"
  229.                 " Lord Of Hosts!");
  230.    if (!(MPort = CreatePort("Shogun Port",0))) errorstop("No Message Port!");
  231.    if (!(IOReq = CreateStdIO(MPort))) errorstop("No StdIORequest!");
  232.    if (OpenDevice("input.device",0,(struct IORequest *)IOReq,0))
  233.       errorstop("No input.device!");
  234.    JoyMouseData=SPEED;
  235.    if (!(MyScreen = OpenScreen(&TheScreen))) errorstop("No Screen!");
  236.    VP = &(MyScreen->ViewPort);
  237.    TheWindow.Screen = MyScreen;
  238.    if (!(MyWindow = OpenWindow(&TheWindow))) errorstop("No Window!");
  239.    RP = MyWindow->RPort;
  240.    BM = RP->BitMap;        /* BitMap, in der die Spielsteine bewegt werden */
  241.    InitBitMap(&PiecesBM,4,21,21);  /* 4 Planes, 21*21 Pixel */
  242.    for (i=0;i<4;++i)
  243.       if (!(PiecesBM.Planes[i]=AllocRaster(21,21)))
  244.          errorstop("No BitMap Memory!");
  245.    LoadRGB4(VP,MyColorMap,16);
  246.    if (!(MyFont = OpenFont(&TheFont))) errorstop("No font topaz.8!");
  247.    SetFont(RP,MyFont);
  248.    CurrentTime(&sec,&mic);   /* Zufallsgenerator setzen */
  249.    srand((unsigned int)sec);
  250.    SetMenuStrip(MyWindow, &game_m);
  251.     MyProcess = (struct Process *)FindTask(NULL);
  252.     OldErrorWindow = MyProcess->pr_WindowPtr;
  253.     MyProcess->pr_WindowPtr = (APTR)MyWindow;
  254. }
  255.  
  256. void close_all(void)
  257. {
  258.    int i;
  259.    if (ReqBase) PurgeFiles(&MyFileReqStruct); /* Speicher vom Filerequester */
  260.    if (MyFont) CloseFont(MyFont);
  261.    for (i=0;i<4;++i)
  262.       if (PiecesBM.Planes[i])
  263.          FreeRaster(PiecesBM.Planes[i],21,21);
  264.    if (MyWindow)
  265.    {
  266.        MyProcess->pr_WindowPtr = OldErrorWindow;
  267.       ClearMenuStrip(MyWindow);
  268.       CloseWindow(MyWindow);
  269.    }
  270.    if (MyScreen) CloseScreen(MyScreen);
  271.    if (IOReq)
  272.    {
  273.       CloseDevice((struct IORequest *)IOReq);
  274.       DeleteStdIO(IOReq);
  275.    }
  276.    if (MPort) DeletePort(MPort);
  277.    if (ReqBase) CloseLibrary(ReqBase);
  278.    if (GfxBase) CloseLibrary(GfxBase);
  279.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  280.    exit(0);
  281. }
  282.